package com.sanben.project.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.sanben.common.web.domain.Result;
import com.sanben.project.data.dto.ProjectReleaseDto;
import com.sanben.project.data.req.ProjectReleaseReq;
import com.sanben.project.data.vo.ProjectReleaseVo;
import com.sanben.project.entity.ProjectRelease;
import com.sanben.project.service.IProjectReleaseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @author cyh
 * @description: 项目发布表 控制器
 * @date: 2020-08-11
 */
@RestController
@RequestMapping("projectRelease")
@Api(tags = "项目发布表相关接口")
public class ProjectReleaseController {

    @Autowired
	private IProjectReleaseService projectReleaseService;

	@GetMapping("/page")
	@ApiOperation(value = "外包驻场", notes = "传入projectReleaseReq")
	public Result<IPage<ProjectReleaseVo>> page(ProjectReleaseReq req) {
		IPage<ProjectReleaseVo> pages = projectReleaseService.page(req);
		return Result.data(pages);
	}

	@GetMapping("/home/list")
	@ApiOperation(value = "首页-最新项目")
	public Result<List<ProjectReleaseVo>> getHomeList() {
		List<ProjectReleaseVo> list = projectReleaseService.getHomeList();
		return Result.data(list);
	}

	@GetMapping("/{id}")
	@ApiOperation(value = "详情", notes = "传入id")
	public Result<ProjectRelease> detail(@PathVariable Integer id) {
	    ProjectRelease detail = projectReleaseService.detail(id);
		return Result.data(detail);
	}

	@PostMapping
	@ApiOperation(value = "新增", notes = "传入projectRelease")
	public Result save(@Valid @RequestBody ProjectReleaseDto dto) {
		return Result.data(projectReleaseService.save(dto));
	}

	@PutMapping
	@ApiOperation(value = "修改", notes = "传入projectRelease")
	public Result update(@RequestBody ProjectReleaseDto dto) {
		return Result.data(projectReleaseService.updateById(dto));
	}

	@DeleteMapping("/{ids}")
	@ApiOperation(value = "逻辑删除", notes = "传入ids")
	public Result remove(@PathVariable List<Integer> ids) {
		return Result.data(projectReleaseService.deleteLogic(ids));
	}

}
